<span id="${uuid}"></span>
<div class="box_tc_s">
    <form data-id="form-horizontal-resource-add" method="post"
          action="${pageContext.request.contextPath}/app/api/resource/addResourceForJson">
        <table border="1" class="hydra-table" cellpadding="0" cellspacing="0">
            <tr class="hydra-tr-bg">
                <td class="hydra-left">资源名称：</td>
                <td class="hydra-right"><input type="text" data-id="resourceName"
                                               name="resourceName" class="easyui-validatebox hydra-input-width"
                                               data-options="required:true,validType:['normalChar','length[0,20]']"
                                               placeholder="资源名称.." value=""/></td>
            </tr>
            <tr>
                <td class="hydra-left">资源类型：</td>
                <td class="hydra-right"><input type="radio" name="resourceType" data-id="button"
                                               value="menu" checked>菜单 <input type="radio"
                                                                              name="resourceType" value="button">其他
                </td>
            </tr>
            <tr>
                <td class="hydra-left">资源图标：</td>
                <td class="hydra-right">
                    <input type="text" data-id="uploadCover" name="icon"  />
                </td>
            </tr>
            <tr class="hydra-tr-bg">
                <td class="hydra-left">资源路径:</td>
                <td class="hydra-right"><input type="text" data-id="resourceUrl"
                                               autocomplete="off" name="resourceUrl" class="easyui-validatebox hydra-input-width"
                                               data-options="validType:['length[0,200]']"
                                               placeholder="资源路径.." value=""/></td>
            </tr>
            <tr>
                <td class="hydra-left">权限码：</td>
                <td class="hydra-right"><input type="text"
                                               data-id="resource_permission" autocomplete="off" name="permission"
                                               class="easyui-validatebox hydra-input-width"
                                               data-options="required:true,validType:['normalCharPermission','length[0,50]']"
                                               placeholder="resource:data:update" value=""/></td>
            </tr>
            <tr>
                <td class="hydra-left">父级资源：</td>
                <td class="hydra-right">
                    <select name="parentId" style="width: 360px" data-id="parentId" class="hydra-input-width"></select>
                    <a href="#" data-id="reset" iconCls="fa fa-times-circle fa-lg" plain="true">重置</a>
            </tr>
            <tr>
                <td class="hydra-left">资源序号：</td>
                <td class="hydra-right">
                    <input type="text" autocomplete="off" name="orderNo"
                           class="easyui-validatebox easyui-numberbox hydra-input-width"
                           data-options="required:true,min:0" value="0"/>
                </td>
            </tr>
            <tr class="hydra-tr-bg">
                <td class="hydra-left">资源状态：</td>
                <td class="hydra-right">
                    <input type="checkbox" data-id="available" name="available" checked value="1"/>
                </td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
    seajs.use(["apps/file", "apps/easyui"], function(){
        var uuid = "${uuid}";
        var page = new $.PageDomFactory(uuid);
        page.getJqDom("resourceType").combobox({
            editable: false
        });
        page.getJqDom("available").toggleButton({
            dataRef:{
                "0":"禁用",
                "1":"启用"
            }
        });
        page.getJqDom("parentId").resourceSelect({
            url:"${ctx}/app/api/resource/queryResourceByPageForJson?resourceType=menu",
            form:{
                items:['<span class="mr10">按资源名称：</span><input name="resourceName" class="hydra-input-width" placeholder="资源名称..."/>']
            }
        });
        page.getJqDom("reset").linkbutton({
            onClick: function () {
                page.getJqDom("parentId").resourceSelect("clear");
            }
        });
        page.getJqDom('uploadCover').baseImageUpload({
            imageSize:[16, 16],
            'uploader' : '${ctx}/app/api/file/uploadTempFile'
        });
        $[uuid] = {
            pageFactory: page
        }
    });

    function resource_add_save(win) {
        if (!$["${uuid}"].pageFactory.getJqDom('form-horizontal-resource-add').form('validate')) {
            return false;
        }
        win.wait("start", "保存中,请稍候.");
        var form = $["${uuid}"].pageFactory.getJqDom("form-horizontal-resource-add");
        var postData = form.serializeJson();
        $.post(form.attr(
                        "action")
                        + "?random=" + Math.random(), $.utils.buildJson(postData),
                function (json) {
                    win.wait("end");
                    if ($.isPlainObject(json) && json.error) {
                        $.messager.alert('信息',
                                json.msg, 'info');
                    } else {
                        $.messager.alert('信息',
                                '保存成功', 'info');
                        win.callback(true);
                        win.close();
                    }
                }, "json");
    }
</script>
